package controllers

import (
	"fmt"
	beego "github.com/beego/beego/v2/server/web"
) //正则路由控制器

type RegController struct {
	beego.Controller
}

func (this *RegController) Get() {

	//*全匹配
	//logs.Info("全匹配：" + this.Ctx.Input.URL())
	//this.Ctx.Output.Body([]byte("请求URL：" + this.Ctx.Input.URL()))

	//变量匹配
	//idid := this.Ctx.Input.Param(":idid")
	//logs.Info("Id:" + idid)
	//this.Ctx.ResponseWriter.Write([]byte("Id:" + idid))

	//*.*匹配
	//path := this.Ctx.Input.Param(":path")
	//logs.Info(path)
	//ext := this.Ctx.Input.Param(":ext")
	//logs.Info(ext)
	//this.Ctx.ResponseWriter.Write([]byte("filePath: " + path + " , ext: " + ext))

	//int类型匹配 只能匹配int类型的
	id := this.Ctx.Input.Param(":id")
	if id != "" {
		fmt.Println("匹配到 int 类型路由，id:", id)
	}
	this.Ctx.ResponseWriter.Write([]byte("int类型变量值：" + id))

	//string类型匹配 只能匹配string类型
	userName := this.Ctx.Input.Param(":username")
	if userName != "" {
		fmt.Println("匹配到 string 类型路由，username:", userName)
	}
	this.Ctx.ResponseWriter.Write([]byte("string类型变量值：" + userName))
}

/*func (c *RegController) Get() {
	id := c.Ctx.Input.Param(":id")
	userName := c.Ctx.Input.Param(":username")

	// 打印日志，确认匹配情况
	if id != "" {
		fmt.Println("匹配到 int 类型路由，id:", id)
	}
	if userName != "" {
		fmt.Println("匹配到 string 类型路由，username:", userName)
	}

	c.Ctx.ResponseWriter.Write([]byte("int类型变量值：" + id + "\n"))
	c.Ctx.ResponseWriter.Write([]byte("string类型变量值：" + userName))
}*/
